import 'package:flutter/cupertino.dart';

import '../regex_util.dart';
import '../string_util.dart';

class SpecialTextBean{
  static const int TYPE_NONE = -1;
  static const int TYPE_PROJECT = 1;
  static const int TYPE_USER = 2;
  static const int TYPE_URL = 3;
  static const int TYPE_TOPIC = 4;

  int type;
  int id;
  String value;

  SpecialTextBean({@required this.type, this.id, @required this.value});

  @override
  String toString() {
    return "SpecialTextBean{type:$type, id:$id, value:$value}";
  }

  static int getType(String flag){
    String classType = RegexUtil.getAttrValueFromHtmlTag(flag, ".*", "class");
    String rel = RegexUtil.getAttrValueFromHtmlTag(flag, ".*", "rel");
    String href = RegexUtil.getAttrValueFromHtmlTag(flag, ".*", "href");
    int type = 0;
    if(!StringUtil.isEmpty(classType)){
      if(classType.compareTo("project") == 0){
        type = TYPE_PROJECT;
      } else if(classType.compareTo("referer") == 0){
        type = TYPE_USER;
      }
    } else if(href.contains("tweet-topic")){
      type = TYPE_TOPIC;
    } else if(!StringUtil.isEmpty(rel) || !StringUtil.isEmpty(href)){
      type = TYPE_URL;
    } else {
      return TYPE_NONE;
    }
    return type;
  }
}